home *** CD-ROM | disk | FTP | other *** search
- #!/bin/csh -f
-
- set prog = `/usr/bin/basename $0`
- set usage = "Usage: $prog package chunk-size(in KB) [-p pad-size] [-d dest-dir]"
-
- set noglob
-
- # gather parameters
- if ($#argv == 0) then
- echo $usage
- exit(1)
- endif
-
- while ( $#argv > 0 )
- switch ( $argv[1] )
- case -d:
- if ( $?destDir ) then
- echo ${prog}: dest-dir parameter already set to $destDir.
- echo $usage
- exit(1)
- else if ( $#argv < 2 ) then
- echo ${prog}: -d option requires destination directory.
- echo $usage
- exit(1)
- else
- set destDir = "$argv[2]"
- shift; shift
- breaksw
- endif
- case -p:
- if ( $?padSize ) then
- echo ${prog}: pad-size parameter already set to $padSize.
- echo $usage
- exit(1)
- else if ( $#argv < 2 ) then
- echo ${prog}: -p option requires value.
- echo $usage
- exit(1)
- else if ( $argv[2] !~ [0-9]* ) then
- echo ${prog}: -p option requires positive numerical value.
- echo $usage
- exit(1)
- else
- @ padSize = $argv[2]
- shift; shift
- breaksw
- endif
- case -*:
- echo ${prog}: Unknown option: $argv[1].
- echo $usage
- exit(1)
- case *.pkg:
- if ( $?bigPackage ) then
- echo ${prog}: big-package parameter already set to $bigPackage.
- echo $usage
- exit(1)
- else
- set bigPackage = $argv[1]
- shift
- breaksw
- endif
- case [0-9]*:
- if ( $?chunkSize ) then
- echo ${prog}: chunk-size parameter already set to $chunkSize.
- echo $usage
- exit(1)
- else
- @ chunkSize = $argv[1]
- shift
- breaksw
- endif
- default:
- if ( $?bigPackage ) then
- echo ${prog}: unrecognized parameter: $argv[1]
- echo $usage
- exit(1)
- else if ( ! -d $argv[1].pkg ) then
- echo ${prog}: $argv[1].pkg does not exist.
- echo $usage
- exit(1)
- else
- set bigPackage = "$argv[1].pkg"
- shift
- breaksw
- endif
- endsw
- end
-
- # check for mandatory parameters
- if ( ! $?bigPackage) then
- echo ${prog}: missing big-package parameter.
- echo $usage
- exit(1)
- else if ( ! $?chunkSize) then
- echo ${prog}: missing chunk-size parameter.
- echo $usage
- exit(1)
- endif
-
- # check for valid pad size
- if ( $?padSize ) then
- if ( $padSize <= 0 ) then
- echo ${prog}: pad-size must be greater than 0.
- exit(1)
- else if ( $padSize >= $chunkSize ) then
- echo ${prog}: pad-size must be less than chunk-size.
- exit(1)
- endif
- endif
-
- unset noglob
-
- # destDir gets default value if unset on command line
- if ( $?destDir ) then
- /bin/mkdirs $destDir
- set olddir = `pwd`
- cd $destDir
- set destDir = `/bin/pwd`
- cd $olddir
- else
- set destDir = `/bin/pwd`
- endif
-
- # derive the root name from the big package
- set root = `/usr/bin/basename ${bigPackage} .pkg`
-
- # get the floppy disk pattern
- if ( -f ${bigPackage}/${root}.info ) then
- set infofile = ${bigPackage}/${root}.info
- else if ( -f ${bigPackage}/English.lproj/${root}.info ) then
- set infofile = ${bigPackage}/English.lproj/${root}.info
- else
- set infofile = `find ${bigPackage} -name '*.info' -print | head -1`
- endif
-
- if ( "$infofile" == "" ) then
- set pattern = "${root} #%d"
- else
- set pattern = `/usr/bin/fgrep -i DiskName $infofile | /bin/sed 's/^[Dd][Ii][Ss][Kk][Nn][Aa][Mm][Ee]//'`
- if ( "${pattern}" == "" || "`echo ${pattern} | /usr/bin/fgrep '%d'`" == "" ) then
- set pattern = "${root} #%d"
- endif
- endif
-
- # generate the chunked packages
- echo Chunking $bigPackage ...
-
- # convert kBytes to bytes
- @ chunkSize *= 1024
- if ( $?padSize ) @ padSize *= 1024
-
- # chunk the archive
- set bigArchive = ${bigPackage}/${root}.tar.Z
- echo -n " creating archive chunks ... "
- if ( $?padSize ) then
- /NextAdmin/Installer.app/chunk $chunkSize +$padSize $bigArchive $destDir
- echo done.
- else
- /NextAdmin/Installer.app/chunk $chunkSize $bigArchive $destDir
- echo done.
- endif
-
- # loop, generating small packages
- @ i = 1
- set chunk = ${root}.tar.Z.$i
- cd ${bigPackage}
-
- while ( -e $destDir/$chunk )
-
- # create small package directory
- set destSubDir = `echo ${pattern} | /bin/sed "s/%d/${i}/g"`
- set destPkg = "${destDir}/${destSubDir}/${root}.pkg"
- echo -n " creating $destPkg ... "
- if ( -e "${destDir}/${destSubDir}" ) /bin/rm -rf "${destDir}/${destSubDir}"
- if ( ! -d "${destDir}" ) /bin/mkdirs -m 755 "${destDir}"
- /bin/mkdir "${destDir}/${destSubDir}"
- /bin/chmod 755 "${destDir}/${destSubDir}"
- /bin/mkdir "$destPkg"
- /bin/chmod 755 "$destPkg"
-
- # copy files into small package directory
- foreach file ( *.info *.sizes *.tiff *.bom *.lproj *.pre_install *.post_install *.pre_delete *.post_delete )
- /bin/cp -rp ${file} "$destPkg"
- end
-
- # move archive chunk into small package directory
- /bin/cp -p $destDir/$chunk "$destPkg"
- /bin/rm -f $destDir/$chunk
- /bin/chmod 444 "$destPkg"/$chunk
-
- @ i++
- set chunk = ${root}.tar.Z.$i
- echo done.
-
- end
- /usr/bin/touch "$destPkg"/.last
-
- echo " ... finished chunking $bigPackage."
- exit(0)
-
- # end chunkPackage
-
-